write_delimited_table Subroutine

public subroutine write_delimited_table(fname, table, delimiter, write_header, real_fmt)

Writes a data_table to a delimited text file, replacing any existing file.

The file contents are assembled in memory and written to disk with a single operation. Rows end with a line feed. NaN values in real columns are written as empty (missing) fields. Logical values are written as T or F. Strings and column names are enclosed in double quotes, with embedded quotes doubled, when they contain the delimiter, a quote, or a line break, or begin or end with a space or tab. The output can be read with read_delimited_table; note, however, that string columns whose values all resemble numbers or logicals will be read back with the inferred type.

The following errors terminate the program via error stop:

  • FS_INVALID_INPUT_ERROR: the delimiter is invalid, or the file cannot be opened or written.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fname

The name of the file to write.

class(data_table), intent(in) :: table

The data_table to write.

character(len=1), intent(in), optional :: delimiter

The field delimiter. The default is a comma. The delimiter must not be a double quote, carriage return, or line feed.

logical, intent(in), optional :: write_header

Set to true to write the column names as the first row, or false to omit them. The default is true.

character(len=*), intent(in), optional :: real_fmt

An optional Fortran edit descriptor, without parentheses, used for real values (e.g. "ES24.16E3" for full double precision). If omitted, the real_column default formatting is used.